<script type="text/javascript">
	function filter() {
		 var date = $("#txtDate_order").datepicker({dateFormat: 'd-m-Y'}).val();
         var status = document.getElementById("status_list").value;
         console.log(status);
         console.log(date);
        $("#filter").attr("href" ,"<?php echo site_url("welcome/orders")?>" + "/" + status + "/" + date);
	}
	$( document ).ready(function() {
		var status = document.getElementById("status_list");
		var date = document.getElementById("txtDate_order");
		date.value = '<?php echo $date; ?>' ;	
		status.value = '<?php echo $status; ?>';
	});  
</script>
<div class="row-fluid sortable">		
    <div class="box span12">
        <div class="box-header well" data-original-title>
            <h2><i class="icon-user"></i> Hóa đơn </h2>

        </div>
        <div class="box-content">
		<label class="control-label" for="typeahead">Chọn ngày</label>
            <script type="text/javascript">
            	 	
                $(function() {
                    $('#txtDate_order').datepicker({dateFormat: 'dd-mm-yy'});
                });
            </script>
            <input id="txtDate_order" type="text" onchange ="filter()" >
         <label class="control-label" for="typeahead">Trạng thái</label>
            <select name="status_list" id="status_list" onchange ="filter()">     
                <option value="100" selected="selected">Tất cả trạng thái</option>
                <option value="0" selected="selected">Chưa thanh toán</option>
                <option value="1" selected="selected">Đã thu tiền</option>
                <option value="2" selected="selected">Chờ thu tiền</option>
                
            </select>
            <a class="btn btn-primary" id="filter" href="">Lọc</a>        
            <?php echo form_open_multipart('welcome/checkout_multi_order'); ?>
            <legend>	<a href="<?php echo site_url("welcome/add_order"); ?>"  > Nhập order</a></legend>
            <input type="submit" name="submit_multi" class="btn btn-primary" value="Ghép bàn">
            <table class="table table-striped table-bordered bootstrap-datatable datatable">
                <thead>
                    <tr>
                        <th></th>
                        <th>Người tạo</th>
                        <th>Tên bàn</th> 
                        <th>Tình trạng</th>  
                        <th>Giờ</th>
                        <th>Actions</th>
                    </tr>
                </thead>   
                <tbody>

                    <?php foreach ($order_list as $order): ?> 
                        <tr>
                            <td>  
                                <?php if ($order->status == 0): ?> 
                                <input type="checkbox" name="order_id_list[]" value="<?php echo $order->id ?>">
                                <?php endif;?>
                            </td>
                            <td>
                                <?php foreach ($user_list as $user): ?>
                                    <?php if ($order->user_id == $user->id): ?>
                                        <?php echo $user->username; ?>
                                    <?php endif; ?>
                                <?php endforeach; ?> 
                            </td>
                            <td>

                                <?php if ($this->session->userdata('usertype') == 3): ?>
                                    <?php if ($order->status == 2): ?>
                                        <?php echo $order->order_name; ?>
                                        <?php elseif($order->status == 0):?>
                                 <a href="<?php echo site_url('welcome/edit_order/' . $order->id); ?>"><?php echo $order->order_name; ?></a>
                                    <?php endif; ?>
                                <?php else: ?>
                                    <a href="<?php echo site_url('welcome/edit_order/' . $order->id); ?>"><?php echo $order->order_name; ?></a>
                                <?php endif; ?>
                            </td> 
                            <td class="center">
                                <?php if ($order->status == 0): ?>
                                    <span class="label label-warning">Chưa thanh toán</span>
                                <?php elseif ($order->status == 2): ?>
                                	<?php if($order->root_order>0):?>
                                    <span class="label label-pending">Chờ thu tiền, bàn <?php echo $order->root_order_name;?> trả</span>
                                    <?php else :?>
                                    <span class="label label-pending">Chờ thu tiền</span>
                                    <?php endif;?>
                                <?php else: ?>
                                    <span class="label label-success">Đã thu tiền</span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <?php echo $order->time_create; ?>
                            </td>
                            <td class="center">
                                <?php if ($order->status == 0): ?>
                                    <?php if ($this->session->userdata('usertype') == 3): ?>
                                        <a class="btn btn-primary" href="<?php echo site_url("welcome/edit_order/" . $order->id ."/1"); ?>">Yêu cầu thanh toán</a>
                                        <a href="<?php echo site_url('welcome/edit_order/' . $order->id); ?>">Sửa</a> &nbsp;
                                        <a href="<?php echo site_url("welcome/del_order/" . $order->id); ?>"> Xóa</a>
                                    <?php else: ?>
                                   		<?php if(!$order->root_order>0):?>
                                   		    <?php if($order->status == 0):?>
                            				<a class="btn btn-primary" href="<?php echo site_url("welcome/checkout_pending/" . $order->id); ?>">Báo Thanh toán</a>
                        				<?php endif;?>
                        				<?php if($order->status == 2):?>
                            				<a class="btn btn-primary" href="<?php echo site_url("welcome/checkout/" . $order->id ."/1"); ?>"> Thu tiền</a>
                        				<?php endif;?>
                                     	<?php if ($order->status == 0): ?>                         
                                        <a href="<?php echo site_url('welcome/edit_order/' . $order->id); ?>">Sửa</a> &nbsp;
                                        <a href="<?php echo site_url("welcome/del_order/" . $order->id); ?>"> Xóa</a>
                                       	<?php endif;?>
                                       	<?php endif;?>
                                        
                                    <?php endif; ?> 
                                <?php endif; ?>
                                <?php if ($order->status == 2): ?>
                                    <?php if ($this->session->userdata('usertype') <> 3): ?>
                                       	<?php if(!$order->root_order>0):?>
                                        <a class="btn btn-primary" href="<?php echo site_url("welcome/edit_order/" . $order->id ."/1"); ?>">Thu tiền</a>
                                        <?php if ($order->status == 0): ?>                         
                                        <a href="<?php echo site_url('welcome/edit_order/' . $order->id); ?>">Sửa</a> &nbsp;
                                        <a href="<?php echo site_url("welcome/del_order/" . $order->id); ?>"> Xóa</a>
                                       	<?php endif;?>
                                       	<?php endif;?>
                                        
                                    <?php endif; ?>
                                <?php endif; ?>
                            </td>
                        </tr>
                    <?php endforeach; ?>

                </tbody>
            </table>            
            <?php echo form_close(); ?>
        </div>
    </div><!--/span-->

</div><!--/row-->